﻿#pragma once

#include "Ability/EditorAbilityModel.h"
#include "EditorDebugConsoleModel.m.h"

RENUM()
enum class EDebugConsoleLineType
{
    EditorNormal=0, //editor output
    Normal, //debuging process normal output
};


RSTRUCT()
struct SDebugConsoleLine
{
    ROBJECT
    
    SDebugConsoleLine() = default;

    SDebugConsoleLine(const CString& InLine)
        : Content(InLine)
    {
    }

    RFIELD()
    CString Content;

    RFIELD()
    EDebugConsoleLineType LineType = EDebugConsoleLineType::EditorNormal;
};

RCLASS()
class REditorDebugConsoleModel : public REditorAbilityModel
{
    ROBJECT

public:
    virtual void FirstTimeInitializeObject() override;
    virtual void PostLoadFromAsset()  override;

    virtual CString GetName() const override { return U"调试控制台"; }

    void AddLine(const CString& InLine, EDebugConsoleLineType InLineType = EDebugConsoleLineType::EditorNormal);
    TDelegate<void> OnLineNumChanged;
    void ClearLines();
    int64_t GetLineNum() const { return Lines.Num(); }
    const SDebugConsoleLine& GetLine(int64_t InIndex) const { return Lines[InIndex]; }

protected:

    int64_t InitialMemorySize = 1024;
    TVector<SDebugConsoleLine> Lines;

    RFUNCTION()
    void OnPrint(const CString& InNewMessage);

    RFUNCTION()
    void OnDebugSessionStarted();
};